<?php /*a:2:{s:65:"/www/wwwroot/yinglinet.cn/app/admin/view/admin/src/auseredit.html";i:1699343570;s:57:"/www/wwwroot/yinglinet.cn/app/admin/view/base/unitjs.html";i:1699343568;}*/ ?>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>表单页面</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
</head>

<body>
    <form class="layui-form" action="" id="formId">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">头像</label>
                    <div class="layui-input-block" >
                        <div onclick="uploadImg(this)" style="float: left;">
                        <img  src="/static/efile/auserimg/<?php echo htmlentities((isset($msg['img']) && ($msg['img'] !== '')?$msg['img']:'default.jpg')); ?>" id="headImgId" class="layui-nav-img" style="border: solid #000 1px;cursor: pointer;">
                        </div>
                    </div>
                    <input type="file" name="img" style="display:none;" id="fileId">
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" value="<?php echo htmlentities((isset($msg['username']) && ($msg['username'] !== '')?$msg['username']:'')); ?>" lay-verify="title" autocomplete="off"
                            placeholder="请输入账号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" value="<?php echo htmlentities((isset($msg['password']) && ($msg['password'] !== '')?$msg['password']:'')); ?>" lay-verify="title" autocomplete="off" placeholder="请输入密码"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="nickname" value="<?php echo htmlentities((isset($msg['nickname']) && ($msg['nickname'] !== '')?$msg['nickname']:'')); ?>" lay-verify="title" autocomplete="off"
                            placeholder="请输入昵称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="reaname" value="<?php echo htmlentities((isset($msg['reaname']) && ($msg['reaname'] !== '')?$msg['reaname']:'')); ?>" lay-verify="title" autocomplete="off" placeholder="请输入姓名"
                            class="layui-input">
                    </div>
                </div>
                
                
                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" value="<?php echo htmlentities((isset($msg['mobile']) && ($msg['mobile'] !== '')?$msg['mobile']:'')); ?>" lay-verify="title" autocomplete="off"
                            placeholder="请输入电话" class="layui-input">
                    </div>
                </div>
                <?php if(!app('request')->get('t')): ?>
                <div class="layui-form-item">
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        <select name="role_id" lay-verify="title">
                            <option value="0">请选择一个角色</option>
                            <?php $role_id=empty($msg) ? 0 : $msg['role_id'];  if(is_array($lst) || $lst instanceof \think\Collection || $lst instanceof \think\Paginator): $i = 0; $__LIST__ = $lst;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                            <option value="<?php echo htmlentities($vo['id']); ?>" <?php if($role_id == $vo['id']): ?> selected <?php endif; ?>><?php echo htmlentities($vo['name']); ?></option>
                            <?php endforeach; endif; else: echo "" ;endif; ?>
                        </select>
                    </div>
                </div>
                <?php endif; if(!app('request')->get('t')): ?>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <?php  
                            $status=[
                                0=> empty($msg['status']) ? "checked" : "",
                                1=> empty($msg['status']) ? "" : "checked",
                            ];
                         ?>
                        <input type="radio" name="status" value="0" title="开启" <?php echo htmlentities($status[0]); ?>>
                        <input type="radio" name="status" value="1" title="冻结" <?php echo htmlentities($status[1]); ?>>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
        <script src="/static/user/js/jquery.min.js"></script>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script>
         
            function uploadImg(item) {
                $("#fileId").click();
            }
            $("#fileId").change(function () {
                if ($(this).val()) {
                    var imgurl = getObjectURL(this.files[0]);
                    $("#headImgId").attr("src", imgurl);
                }
            });
          function getObjectURL(file) {
                var url = null;
                if (window.createObjectURL != undefined) { // basic
                    url = window.createObjectURL(file);
                } else if (window.URL != undefined) { // mozilla(firefox)
                    url = window.URL.createObjectURL(file);
                } else if (window.webkitURL != undefined) { // webkit or chrome
                    url = window.webkitURL.createObjectURL(file);
                }
                return url;
            }


        layui.use(['form', 'jquery'], function () {
            let form = layui.form;
            let $ = layui.jquery;
            
            form.on('submit(form-save)', function (data) {
                //var data = data.field ;//JSON.stringify(data.field);
                var data = $("#formId");
                '<?php if(!app('request')->get('t')): ?>'
                       var url="<?php echo url('admin/auserSave'); ?>?id=<?php echo htmlentities(app('request')->get('id')); ?>";
                '<?php else: ?>'
                    var url="<?php echo url('admin/auserSave'); ?>?id=<?php echo htmlentities(app('request')->session('lt_auser.id')); ?>&t=1";
                '<?php endif; ?>'
                postDatai(url,data).then(function(res){
                    if (res.code==200) {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                               '<?php if(!app('request')->get('t')): ?>'
                                    parent.layui.table.reload("tableId");
                                '<?php endif; ?>'
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2,
                            time: 1000
                        });
                    }
                });
                return false;
            });
        })
    </script>
    <script>








    //     参数解释  
    //  url 地址  
    //  data  数据  
    //  alt 进度提示内容  
    //  ins 0 手动处理返回信息  1 自动处理返回信息
    //     co[辅助alt  co = 0时  进度条默认关闭  co = 1时  手动关闭进度条及之后弹框的内容]


    //带文件提交
    function postDatai(url, form, alt = "", ins = 0) {
        var p = new Promise(function (resolve, reject) {
            var formData = new FormData(form[0]);
            $.ajax({
                url: url,
                type: 'POST',
                data: formData,
                dataType: 'json',
                async: true,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res.code == -1) {
                        layer.alert(res.msg, {
                            title: "提示",
                            closeBtn: 0,
                            yes: function () {
                                location.reload();
                            }
                        });
                        return;
                    }
                    if (!ins) {
                        resolve(res);
                        return;
                    }
                    layer.alert(res.msg, {
                        title: "提示",
                        closeBtn: 0,
                        yes: function () {
                            res.code == 200 ? location.reload() : layer.close(layer.index);
                            return;
                        }
                    });


                },
                error: function (e) {
                    var res = $.parseJSON(e.responseText);
                    layer.alert(res.message, {
                        title: '提示',
                        closeBtn: 0,
                    });
                },
                beforeSend: function () {
                    if (alt) {
                        layer.msg(alt, { icon: 16, shade: 0.4, time: false });
                    }

                },
                complete: function () {
                    if (alt) {
                        layer.close(layer.index);
                    }
                }

            });
        })
        return p;
    }




    //普通提交--整改
    function postData(url, data, alt = "", ins = 0, co = 0) {
        var p = new Promise(function (resolve, reject) {
            $.ajax({
                url: url,
                data: data,
                header: { 'content-type': 'application/json' },
                type: 'POST',
                dataType: 'json',
                responseType: 'text',
                success: function (res) {
                    if (res.code == -1) {
                        layer.alert(res.message, {
                            title: "提示",
                            closeBtn: 0,
                            yes: function () {
                                location.reload();
                            }
                        });
                        return;
                    }
                    if (!ins) {
                        resolve(res);
                        return;
                    }
                    layer.alert(res.message, {
                        title: "提示",
                        closeBtn: 0,
                        yes: function () {
                            res.code == 200 ? location.reload() : layer.close(layer.index);
                            return;
                        }
                    });
                },
                fail: function (res) {
                    console.log(res);

                },
                error: function (e) {
                    var res = $.parseJSON(e.responseText);
                    layer.alert(res.message, {
                        title: '提示',
                        closeBtn: 0,
                    });
                },
                beforeSend: function () {
                    if (alt) {
                        layer.msg(alt, { icon: 16, shade: 0.4, time: false });
                    }

                },
                complete: function () {
                    if (alt && co) {
                        layer.close(layer.index);
                    }
                }

            })

        })
        return p;
    }



    function getObjectURL(file) {
		var url = null;
		if (window.createObjectURL != undefined) { // basic
			url = window.createObjectURL(file);
		} else if (window.URL != undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file);
		} else if (window.webkitURL != undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file);
		}
		return url;
	}
</script>
</body>

</html>